﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ActionSystem.Core;
using System;
using ActionSystem.Core.Ranges;

namespace ActionSystem.Core.ComboLogic
{
    /// <summary>
    /// 获取碰撞盒和返还
    /// </summary>
    public class RangeBoxPool
    {
        /// <summary>
        /// 获取3D碰撞盒
        /// </summary>
        /// <param name="layer">层</param>
        /// <param name="item">range</param>
        /// <returns></returns>
        public static RangeBoxItem GetBoxItem(int unityLayer, IItem item, int layerMask=0)
        {
            //根据Item判断出RangeBoxItem类型,感觉写法不好，
            //能否转换成反射，获取子类，使用attribute判断对应的类型，相同则调用子类函数
            RangeBoxItem box = null;
            switch (item)
            {
                case BoxItem b:
                    box = RangeBoxItem.GetRangeBoxItem<BoxRangeBoxItem>();
                    break;
                case SphereItem s:
                    box = RangeBoxItem.GetRangeBoxItem<SphereRangeBoxItem>();
                    break;
                case CapsuleItem c:
                    box = RangeBoxItem.GetRangeBoxItem<CapsuleRangeBoxItem>();
                    break;
                default:
                    break;
            }   
            if(box!=null)
            {
                box.SetRangeShape(item);
                box.SetLayer(unityLayer, layerMask);
            }            
            return box;
        }

        /// <summary>
        /// 获取2D碰撞盒
        /// </summary>
        /// <param name="layer"></param>
        /// <param name="item"></param>
        /// <returns></returns>
        public static RangeBoxItem2D GetBoxItem2D(int unityLayer, IItem item, int unityLayerMask=0)
        {
            //根据Item判断出RangeBoxItem类型,感觉写法不好，
            //能否转换成反射，获取子类，使用attribute判断对应的类型，相同则调用子类函数
            RangeBoxItem2D box = null;
            switch (item)
            {
                case RectItem r:
                    box = RangeBoxItem2D.GetRangeBoxItem<RectRangeBoxItem>();
                    break;
                case CircleItem c:
                    box = RangeBoxItem2D.GetRangeBoxItem<CircleRangeBoxItem>();
                    break;
                default:
                    break;
            }
            if (box != null)
            {
                box.SetRangeShape(item);
                box.SetLayer(unityLayer, unityLayerMask);
            }
            return box;
        }

        /// <summary>
        /// 放回
        /// </summary>
        public static void PutBoxItem(BaseRangeBoxItem boxItem)
        {
            boxItem?.PoolItemDelete();
        }
    }
}

